﻿using System;
using System.ComponentModel;

namespace HalconDotNet
{
	/// <summary>Represents an instance of an I/O device.</summary>
	// Token: 0x02000045 RID: 69
	public class HIODevice : HHandle
	{
		// Token: 0x0600095B RID: 2395 RVA: 0x0000883B File Offset: 0x00006A3B
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HIODevice() : base(HHandleBase.UNDEF)
		{
		}

		// Token: 0x0600095C RID: 2396 RVA: 0x0003CD2C File Offset: 0x0003AF2C
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HIODevice(IntPtr handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x0600095D RID: 2397 RVA: 0x0003CD3B File Offset: 0x0003AF3B
		[EditorBrowsable(EditorBrowsableState.Never)]
		public HIODevice(HHandle handle) : base(handle)
		{
			this.AssertSemType();
		}

		// Token: 0x0600095E RID: 2398 RVA: 0x0003CD4A File Offset: 0x0003AF4A
		private void AssertSemType()
		{
			base.AssertSemType("io_device");
		}

		// Token: 0x0600095F RID: 2399 RVA: 0x0003CD57 File Offset: 0x0003AF57
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HIODevice obj)
		{
			obj = new HIODevice(HHandleBase.UNDEF);
			return obj.Load(proc, parIndex, err);
		}

		// Token: 0x06000960 RID: 2400 RVA: 0x0003CD70 File Offset: 0x0003AF70
		internal static int LoadNew(IntPtr proc, int parIndex, int err, out HIODevice[] obj)
		{
			HTuple htuple;
			err = HTuple.LoadNew(proc, parIndex, err, out htuple);
			obj = new HIODevice[htuple.Length];
			for (int i = 0; i < htuple.Length; i++)
			{
				obj[i] = new HIODevice(HalconAPI.IsLegacyHandleMode() ? htuple[i].IP : htuple[i].H);
			}
			htuple.Dispose();
			return err;
		}

		/// <summary>
		///   Open and configure an I/O device. 
		///   Modified instance represents: Handle of the opened I/O device.
		/// </summary>
		/// <param name="IOInterfaceName">HALCON I/O interface name. Default: []</param>
		/// <param name="IODeviceName">I/O device name. Default: []</param>
		/// <param name="genParamName">Dynamic parameter names. Default: []</param>
		/// <param name="genParamValue">Dynamic parameter values. Default: []</param>
		// Token: 0x06000961 RID: 2401 RVA: 0x0003CDE0 File Offset: 0x0003AFE0
		public HIODevice(string IOInterfaceName, HTuple IODeviceName, HTuple genParamName, HTuple genParamValue)
		{
			IntPtr proc = HalconAPI.PreCall(2022);
			HalconAPI.StoreS(proc, 0, IOInterfaceName);
			HalconAPI.Store(proc, 1, IODeviceName);
			HalconAPI.Store(proc, 2, genParamName);
			HalconAPI.Store(proc, 3, genParamValue);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(IODeviceName);
			HalconAPI.UnpinTuple(genParamName);
			HalconAPI.UnpinTuple(genParamValue);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Open and configure I/O channels.
		///   Instance represents: Handle of the opened I/O device.
		/// </summary>
		/// <param name="IOChannelName">HALCON I/O channel names of the specified device.</param>
		/// <param name="genParamName">Parameter names. Default: []</param>
		/// <param name="genParamValue">Parameter values. Default: []</param>
		/// <returns>Handles of the opened I/O channel.</returns>
		// Token: 0x06000962 RID: 2402 RVA: 0x0003CE58 File Offset: 0x0003B058
		public HIOChannel[] OpenIoChannel(HTuple IOChannelName, HTuple genParamName, HTuple genParamValue)
		{
			IntPtr proc = HalconAPI.PreCall(2016);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, IOChannelName);
			HalconAPI.Store(proc, 2, genParamName);
			HalconAPI.Store(proc, 3, genParamValue);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(IOChannelName);
			HalconAPI.UnpinTuple(genParamName);
			HalconAPI.UnpinTuple(genParamValue);
			HIOChannel[] result;
			num = HIOChannel.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Open and configure I/O channels.
		///   Instance represents: Handle of the opened I/O device.
		/// </summary>
		/// <param name="IOChannelName">HALCON I/O channel names of the specified device.</param>
		/// <param name="genParamName">Parameter names. Default: []</param>
		/// <param name="genParamValue">Parameter values. Default: []</param>
		/// <returns>Handles of the opened I/O channel.</returns>
		// Token: 0x06000963 RID: 2403 RVA: 0x0003CECC File Offset: 0x0003B0CC
		public HIOChannel OpenIoChannel(string IOChannelName, HTuple genParamName, HTuple genParamValue)
		{
			IntPtr proc = HalconAPI.PreCall(2016);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, IOChannelName);
			HalconAPI.Store(proc, 2, genParamName);
			HalconAPI.Store(proc, 3, genParamValue);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(genParamName);
			HalconAPI.UnpinTuple(genParamValue);
			HIOChannel result;
			num = HIOChannel.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Query information about channels of the specified I/O device. 
		///   Instance represents: Handle of the opened I/O device.
		/// </summary>
		/// <param name="IOChannelName">Channel names to query.</param>
		/// <param name="query">Name of the query. Default: "param_name"</param>
		/// <returns>List of values (according to Query).</returns>
		// Token: 0x06000964 RID: 2404 RVA: 0x0003CF38 File Offset: 0x0003B138
		public HTuple QueryIoDevice(HTuple IOChannelName, HTuple query)
		{
			IntPtr proc = HalconAPI.PreCall(2017);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, IOChannelName);
			HalconAPI.Store(proc, 2, query);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(IOChannelName);
			HalconAPI.UnpinTuple(query);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Query information about channels of the specified I/O device. 
		///   Instance represents: Handle of the opened I/O device.
		/// </summary>
		/// <param name="IOChannelName">Channel names to query.</param>
		/// <param name="query">Name of the query. Default: "param_name"</param>
		/// <returns>List of values (according to Query).</returns>
		// Token: 0x06000965 RID: 2405 RVA: 0x0003CF9C File Offset: 0x0003B19C
		public HTuple QueryIoDevice(string IOChannelName, HTuple query)
		{
			IntPtr proc = HalconAPI.PreCall(2017);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, IOChannelName);
			HalconAPI.Store(proc, 2, query);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(query);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Perform an action on the I/O device.
		///   Instance represents: Handle of the opened I/O device.
		/// </summary>
		/// <param name="action">Name of the action to perform.</param>
		/// <param name="argument">List of arguments for the action. Default: []</param>
		/// <returns>List of result values returned by the action.</returns>
		// Token: 0x06000966 RID: 2406 RVA: 0x0003CFFC File Offset: 0x0003B1FC
		public HTuple ControlIoDevice(string action, HTuple argument)
		{
			IntPtr proc = HalconAPI.PreCall(2018);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, action);
			HalconAPI.Store(proc, 2, argument);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(argument);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Perform an action on the I/O device.
		///   Instance represents: Handle of the opened I/O device.
		/// </summary>
		/// <param name="action">Name of the action to perform.</param>
		/// <param name="argument">List of arguments for the action. Default: []</param>
		/// <returns>List of result values returned by the action.</returns>
		// Token: 0x06000967 RID: 2407 RVA: 0x0003D05C File Offset: 0x0003B25C
		public HTuple ControlIoDevice(string action, string argument)
		{
			IntPtr proc = HalconAPI.PreCall(2018);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, action);
			HalconAPI.StoreS(proc, 2, argument);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Configure a specific I/O device instance.
		///   Instance represents: Handle of the opened I/O device.
		/// </summary>
		/// <param name="genParamName">Parameter names. Default: []</param>
		/// <param name="genParamValue">Parameter values to set. Default: []</param>
		// Token: 0x06000968 RID: 2408 RVA: 0x0003D0B4 File Offset: 0x0003B2B4
		public void SetIoDeviceParam(HTuple genParamName, HTuple genParamValue)
		{
			IntPtr proc = HalconAPI.PreCall(2019);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, genParamName);
			HalconAPI.Store(proc, 2, genParamValue);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(genParamName);
			HalconAPI.UnpinTuple(genParamValue);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Configure a specific I/O device instance.
		///   Instance represents: Handle of the opened I/O device.
		/// </summary>
		/// <param name="genParamName">Parameter names. Default: []</param>
		/// <param name="genParamValue">Parameter values to set. Default: []</param>
		// Token: 0x06000969 RID: 2409 RVA: 0x0003D104 File Offset: 0x0003B304
		public void SetIoDeviceParam(string genParamName, string genParamValue)
		{
			IntPtr proc = HalconAPI.PreCall(2019);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, genParamName);
			HalconAPI.StoreS(proc, 2, genParamValue);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Query settings of an I/O device instance. 
		///   Instance represents: Handle of the opened I/O device.
		/// </summary>
		/// <param name="genParamName">Parameter names. Default: "param_name"</param>
		/// <returns>Parameter values.</returns>
		// Token: 0x0600096A RID: 2410 RVA: 0x0003D148 File Offset: 0x0003B348
		public HTuple GetIoDeviceParam(HTuple genParamName)
		{
			IntPtr proc = HalconAPI.PreCall(2020);
			base.Store(proc, 0);
			HalconAPI.Store(proc, 1, genParamName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(genParamName);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Query settings of an I/O device instance. 
		///   Instance represents: Handle of the opened I/O device.
		/// </summary>
		/// <param name="genParamName">Parameter names. Default: "param_name"</param>
		/// <returns>Parameter values.</returns>
		// Token: 0x0600096B RID: 2411 RVA: 0x0003D1A0 File Offset: 0x0003B3A0
		public HTuple GetIoDeviceParam(string genParamName)
		{
			IntPtr proc = HalconAPI.PreCall(2020);
			base.Store(proc, 0);
			HalconAPI.StoreS(proc, 1, genParamName);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
			return result;
		}

		/// <summary>
		///   Close the specified I/O device. 
		///   Instance represents: Handle of the opened I/O device.
		/// </summary>
		// Token: 0x0600096C RID: 2412 RVA: 0x0003D1F0 File Offset: 0x0003B3F0
		public void CloseIoDevice()
		{
			IntPtr proc = HalconAPI.PreCall(2021);
			base.Store(proc, 0);
			int procResult = HalconAPI.CallProcedure(proc);
			HalconAPI.PostCall(proc, procResult);
			GC.KeepAlive(this);
		}

		/// <summary>
		///   Open and configure an I/O device. 
		///   Modified instance represents: Handle of the opened I/O device.
		/// </summary>
		/// <param name="IOInterfaceName">HALCON I/O interface name. Default: []</param>
		/// <param name="IODeviceName">I/O device name. Default: []</param>
		/// <param name="genParamName">Dynamic parameter names. Default: []</param>
		/// <param name="genParamValue">Dynamic parameter values. Default: []</param>
		// Token: 0x0600096D RID: 2413 RVA: 0x0003D224 File Offset: 0x0003B424
		public void OpenIoDevice(string IOInterfaceName, HTuple IODeviceName, HTuple genParamName, HTuple genParamValue)
		{
			this.Dispose();
			IntPtr proc = HalconAPI.PreCall(2022);
			HalconAPI.StoreS(proc, 0, IOInterfaceName);
			HalconAPI.Store(proc, 1, IODeviceName);
			HalconAPI.Store(proc, 2, genParamName);
			HalconAPI.Store(proc, 3, genParamValue);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(IODeviceName);
			HalconAPI.UnpinTuple(genParamName);
			HalconAPI.UnpinTuple(genParamValue);
			num = base.Load(proc, 0, num);
			HalconAPI.PostCall(proc, num);
			GC.KeepAlive(this);
		}

		/// <summary>Perform an action on the I/O interface.</summary>
		/// <param name="IOInterfaceName">HALCON I/O interface name. Default: []</param>
		/// <param name="action">Name of the action to perform.</param>
		/// <param name="argument">List of arguments for the action. Default: []</param>
		/// <returns>List of results returned by the action.</returns>
		// Token: 0x0600096E RID: 2414 RVA: 0x0003D29C File Offset: 0x0003B49C
		public static HTuple ControlIoInterface(string IOInterfaceName, string action, HTuple argument)
		{
			IntPtr proc = HalconAPI.PreCall(2023);
			HalconAPI.StoreS(proc, 0, IOInterfaceName);
			HalconAPI.StoreS(proc, 1, action);
			HalconAPI.Store(proc, 2, argument);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(argument);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			return result;
		}

		/// <summary>Perform an action on the I/O interface.</summary>
		/// <param name="IOInterfaceName">HALCON I/O interface name. Default: []</param>
		/// <param name="action">Name of the action to perform.</param>
		/// <param name="argument">List of arguments for the action. Default: []</param>
		/// <returns>List of results returned by the action.</returns>
		// Token: 0x0600096F RID: 2415 RVA: 0x0003D2F4 File Offset: 0x0003B4F4
		public static HTuple ControlIoInterface(string IOInterfaceName, string action, string argument)
		{
			IntPtr proc = HalconAPI.PreCall(2023);
			HalconAPI.StoreS(proc, 0, IOInterfaceName);
			HalconAPI.StoreS(proc, 1, action);
			HalconAPI.StoreS(proc, 2, argument);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			return result;
		}

		/// <summary>Query information about the specified I/O device interface.</summary>
		/// <param name="IOInterfaceName">HALCON I/O interface name. Default: []</param>
		/// <param name="query">Parameter name of the query. Default: "io_device_names"</param>
		/// <returns>List of result values (according to Query).</returns>
		// Token: 0x06000970 RID: 2416 RVA: 0x0003D344 File Offset: 0x0003B544
		public static HTuple QueryIoInterface(string IOInterfaceName, HTuple query)
		{
			IntPtr proc = HalconAPI.PreCall(2024);
			HalconAPI.StoreS(proc, 0, IOInterfaceName);
			HalconAPI.Store(proc, 1, query);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HalconAPI.UnpinTuple(query);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			return result;
		}

		/// <summary>Query information about the specified I/O device interface.</summary>
		/// <param name="IOInterfaceName">HALCON I/O interface name. Default: []</param>
		/// <param name="query">Parameter name of the query. Default: "io_device_names"</param>
		/// <returns>List of result values (according to Query).</returns>
		// Token: 0x06000971 RID: 2417 RVA: 0x0003D394 File Offset: 0x0003B594
		public static HTuple QueryIoInterface(string IOInterfaceName, string query)
		{
			IntPtr proc = HalconAPI.PreCall(2024);
			HalconAPI.StoreS(proc, 0, IOInterfaceName);
			HalconAPI.StoreS(proc, 1, query);
			HalconAPI.InitOCT(proc, 0);
			int num = HalconAPI.CallProcedure(proc);
			HTuple result;
			num = HTuple.LoadNew(proc, 0, num, out result);
			HalconAPI.PostCall(proc, num);
			return result;
		}
	}
}
